﻿using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace Model
{
    public class SqlDispatchacar : IDispatchacar
    {
        private readonly AppDbContext _appDbContext;
        public SqlDispatchacar(AppDbContext appDbContext) {
            _appDbContext = appDbContext;
        }
        /// <summary>
        /// 添加申请派车
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public int Add(Dispatchacar d)
        {
          
            _appDbContext.Dispatchacar.AddAsync(d);
            return _appDbContext.SaveChanges();
        }

        public IEnumerable<Dispatchacar> dispatchacar()
        {
            return _appDbContext.Dispatchacar.Include(x => x.Astate);
        }

        public int update(int id,string name)
        {
            var e = _appDbContext.Dispatchacar.Find(id);
            e.Aid = 2;
            e.Travel_leader = name;
            _appDbContext.Dispatchacar.Update(e);
            return _appDbContext.SaveChanges();
        }
    }
}
